# delimit ;
clear ;
cd "replication" ;
set more off ; 

* *************************************************************************** ;
* re-run midline analysis
* *************************************************************************** ;

cd ".." ;
do "./replication/do/table03-midline-knowledge-aggregate.do" ; 

* ***************************************************************************** ;
* regressions, robustness check 1: removing strata fixed effects
* ***************************************************************************** ;

foreach var of varlist score* { ; 

	reg `var' healthonly healthandpay, robust ;
	qui est sto `var'1 ; 
	
	test healthonly = healthandpay ; 
	estadd local titlerow = "" ; 
	estadd scalar fstat = r(F): `var'1 ; 
	estadd scalar pval = r(p): `var'1 ; 

	summarize `var' if control == 1 & e(sample) == 1;
	estadd scalar cmean = r(mean): `var'1 ; 
	estadd scalar csd = r(sd): `var'1 ;

} ;

* ***************************************************************************** ;
* regressions, robustness check 2: clustered standard errors
* ***************************************************************************** ;

foreach var of varlist score* { ; 

	areg `var' healthonly healthandpay, a(strata) robust cluster(waveclass) ;
	qui est sto `var'2 ; 
	
	test healthonly = healthandpay ; 
	estadd local titlerow = "" ; 
	estadd scalar fstat = r(F): `var'2 ; 
	estadd scalar pval = r(p): `var'2 ; 

	summarize `var' if control == 1 & e(sample) == 1;
	estadd scalar cmean = r(mean): `var'2 ; 
	estadd scalar csd = r(sd): `var'2 ;

} ;

* **************************************************************************
* output results from robustness check 1
* ************************************************************************** ;

esttab score*1 using "./output/appendix-table-alternative-specifications-midline-knowledge-aggregate-panelA.tex",
	replace
	drop(_cons) 
	cells(b(label() star fmt(%9.3f %9.3f)) se(par)) 
	star(* 0.10 ** 0.05 *** 0.01) 
	stats(titlerow fstat pval cmean csd N, fmt(%9s %9.3f %9.3f %9.3f %9.3f %9.0f) labels("\(F\)-test, HEE = HEEC" "$\qquad$ \(F\)-statistic" "$\qquad$ \(p\)-value" "Control Mean" "Control SD" "N"))
prehead(\begin{table}[htbp] \centering \normalsize `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"'
		\captionsetup{justification=centering} 
		\caption{Effects on Short-Term Health Knowledge \\ Alternative Regression Specifications}
		\label{appendix-table-alternative-reg-spec-midline}
		\setlength{\tabcolsep}{6pt}
		\begin{tabular*}{0.8\hsize}{p{3.8cm}p{1.9cm}p{1.9cm}p{1.9cm}p{1.9cm}}
		\toprule)
	legend label  booktabs  collabels( , none)
	mgroups(
	"All Topics" 
	"By Topic" 
	, pattern(1 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
	posthead(\midrule \end{tabular*}
	\bigskip
	\captionsetup[sub]{justification=raggedleft} 
	\subcaption*{\normalsize Panel A: Removing Strata Fixed Effects} 
	\vspace{-0.5ex}
	\newcolumntype{C}{>{\centering\arraybackslash}X} 
	\setlength{\tabcolsep}{6pt}
	\begin{tabularx}{0.8\linewidth}{lCCCC}
	\midrule
	&\multicolumn{1}{c}{(1)} &\multicolumn{1}{c}{(2)} &\multicolumn{1}{c}{(3)}
	&\multicolumn{1}{c}{(4)}
	\\ \midrule)
	postfoot(`"\midrule"'  \end{tabularx}) ;
	
* **************************************************************************
*  output results from robustness check 2
* ************************************************************************** ;
	
esttab score*2 using "./output/appendix-table-alternative-specifications-midline-knowledge-aggregate-panelB.tex",
	replace nodepvars nomtitles
	drop(_cons)
	eqlabels(none)
	cells(b(label() star fmt(%9.3f %9.3f)) se(par)) 
	star(* 0.10 ** 0.05 *** 0.01) 
	stats(titlerow fstat pval cmean csd N, fmt(%9s %9.3f %9.3f %9.3f %9.3f %9.0f) labels("\(F\)-test, HEE = HEEC" "$\qquad$ \(F\)-statistic" "$\qquad$ \(p\)-value" "Control Mean" "Control SD" "N"))
	prehead(\bigskip
	\subcaption*{\normalsize Panel B: Clustered Standard Errors }
	\vspace{-0.5ex}
	\setlength{\tabcolsep}{6pt}
	\begin{tabularx}{0.8\hsize}{lCCCC}
	\midrule)
	label booktabs collabels( , none)
	postfoot(`"\midrule"'  \end{tabularx}
	\captionsetup{justification=justified, width=0.8\linewidth} 
	\caption*{\footnotesize \textit{Notes:} This table examines the robustness of the results presented in Table \ref{table-midline-knowledge-aggregate} to different regression specifications. Panel A excludes randomization strata fixed effects from the regression. Panel B uses standard errors clustered at the wave-class level.
	***\$\,p < 0.01$, **\$\,p < 0.05$, *\$\,p<0.10$.
		}
	\end{table}) ;
	
exit ;

